<template>
    <div>
        <el-row :gutter="20">

            <el-col :span="24">
                <el-card shadow="hover">
                    <template #header>
                        <div class="clearfix">
                            <span>修改密码</span>
                        </div>
                    </template>
                    <el-form label-width="90px">
                        <el-form-item label="用户名："> {{ name }} </el-form-item>
                        <el-form-item label="真实姓名："> {{ truename }} </el-form-item>
                        <el-form-item label="旧密码：">
                            <el-input type="password" v-model="form.oldpass"></el-input>
                        </el-form-item>
                        <el-form-item label="新密码：">
                            <el-input type="password" v-model="form.newpass"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit">保存</el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import api from "../api/user";
export default {
    data() {
        return {
            name: '',
            truename: '',
            form: {
                oldpass: '',
                newpass: '',
            },
            isLock:false
        }
    },
    methods: {
        load() {
            api.getInfo().then(({ state, msg }) => {
                if (state) {
                    this.name = msg.name;
                    this.truename = msg.trueName;
                }
            });
        },
        onSubmit() {
            if (!this.form.oldpass) return this.$message.warning('请输入旧密码');
            if (!this.form.newpass) return this.$message.warning('请输入新密码');
            if(this.isLock) return;
            this.isLock=true;
            setTimeout(() => {
                this.isLock=false;
            }, 1000);
            api.updatePwd(this.form).then(({ state, msg }) => {
                this.$message[state?'success':'warning'](msg);
                if(state){
                    this.form.oldpass='';
                    this.form.newpass='';
                }
            });
        }
    },
    mounted() {
        this.load();
    }
}
</script>

<style scoped>
.info {
    text-align: center;
    padding: 35px 0;
}

.info-image {
    position: relative;
    margin: auto;
    width: 100px;
    height: 100px;
    background: #f8f8f8;
    border: 1px solid #eee;
    border-radius: 50px;
    overflow: hidden;
}

.info-image img {
    width: 100%;
    height: 100%;
}

.info-edit {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.info-edit i {
    color: #eee;
    font-size: 25px;
}

.info-image:hover .info-edit {
    opacity: 1;
}

.info-name {
    margin: 15px 0 10px;
    font-size: 24px;
    font-weight: 500;
    color: #262626;
}

.crop-demo-btn {
    position: relative;
}

.crop-input {
    position: absolute;
    width: 100px;
    height: 40px;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
}
</style>